import { computed } from 'vue';
import moment from 'moment';
import { queryPagers } from '/@/api/user/index';
import { queryDics } from '/@/api/dic/index';
import { queryOrgans } from '/@/api/organ/index';

export const clientCall = () => {
	return '';
};
export const dateFormat = computed(() => (date: any) => {
	if (date) return moment(date).format('YYYY-MM-DD');
	return '';
});
export const dateFormatTime = computed(() => (date: any) => {
	if (date) return moment(date).format('YYYY-MM-DD HH:mm:ss');
	return '';
});
export const dateFormats = computed(() => (date: any, format: any) => {
	if (date) return moment(date).format(format);
	return '';
});

export const UploadUrl = computed(() => {
	return import.meta.env.VITE_API_URL + '/common/upload/img';
});

export const EvdencesUploadUrl = computed(() => {
	return import.meta.env.VITE_API_URL + '/evidence/upload';
});

export const EvdencesTempUrl = computed(() => {
	var _bUrl=import.meta.env.VITE_API_URL+'';
	return _bUrl.replace("api","")+ 'img/evicence_temp.xlsx';
});

export const CaseAttachUploadUrl = computed(() => {
	return import.meta.env.VITE_API_URL + '/common/upload/caseattachfile';
});

export const UploadOnlyUrl = computed(() => {
	return import.meta.env.VITE_API_URL + '/common/upload/imgonly';
});

export const evidenceStatusName = computed(() => (code: String) => {
	switch (code) {
		case 'dj':
			return '物品登记';
			break;
		default:
			return '未知';
	}
});
export const getEvidenceStatus = (outType: any) => {
	let EvidenceStatusName = '未知';
	switch (outType) {
		case 0:
			EvidenceStatusName = '已登记';
			break;
		case 1:
			EvidenceStatusName = '已入库';
			break;
		case 2:
			EvidenceStatusName = '已出库';
			break;
	}
	return EvidenceStatusName;
};

export const getOutType = (outType: any) => {
	outType = Number(outType);
	let outTypeTitle = '未知';
	switch (outType) {
		case 1:
			outTypeTitle = '借调';
			break;
		case 2:
			outTypeTitle = '检验';
			break;
		case 3:
			outTypeTitle = '发还';
			break;
		case 4:
			outTypeTitle = '销毁';
			break;
		case 5:
			outTypeTitle = '移交';
			break;
		case 6:
			outTypeTitle = '回库';
			break;
		case 7:
			outTypeTitle = '更换位置';
			break;
		case 8:
			outTypeTitle = '入库';
			break;
	}
	return outTypeTitle;
};
export const initDic = (options) => {
	Promise.all([queryPagers({ PageSize: 1000 }), queryOrgans({ PageSize: 1000 }), queryDics()]).then((res: any) => {
		if (options.tqrs) {
			options.tqrs = res[0].data.data.map((x) => {
				return {
					label: x.name,
					value: x.name,
				};
			});
		}
		if (options.tsrs) {
			options.tsrs = res[0].data.data.map((x) => {
				return {
					label: x.name,
					value: x.userNo,
				};
			});
		}
		if (options.tqdws) {
			options.tqdws = res[1].data.data.map((x) => {
				return {
					label: x.name,
					value: x.name,
				};
			});
		}
		options.dics = res[2].data;
		const dics = res[2].data;
		const tqffId = dics.find((x) => x.code == 'TQFF')?.id;
		const tqbwId = dics.find((x) => x.code == 'TQBW')?.id;
		const ajlbId = dics.find((x) => x.code == 'AJLB')?.id;
		const wzlyId = dics.find((x) => x.code == 'WZLY')?.id;
		const wblbId = dics.find((x) => x.code == 'WZLB')?.id;
		const gzlxId = dics.find((x) => x.code == 'GZLX')?.id;
		const wzxzId = dics.find((x) => x.code == 'WZXZ')?.id;
		const wzdwId = dics.find((x) => x.code == 'WZDW')?.id;
		const ajxzId = dics.find((x) => x.code == 'AJXZ')?.id;
		//处置意见
		const rkczyjId = dics.find((x) => x.code == 'RKCZYJ')?.id;
		if (options.ajxz) {
			options.ajxz = dics
				.filter((x) => x.parentId == ajxzId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}

		if (options.tqffs) {
			options.tqffs = dics
				.filter((x) => x.parentId == tqffId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.rkczyj) {
			options.rkczyj = dics
				.filter((x) => x.parentId == rkczyjId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.tqbws) {
			options.tqbws = dics
				.filter((x) => x.parentId == tqbwId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.ajlbs) {
			options.ajlbs = dics
				.filter((x) => x.parentId == ajlbId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.wzlys) {
			options.wzlys = dics
				.filter((x) => x.parentId == wzlyId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.wzlbs) {
			options.wzlbs = dics
				.filter((x) => x.parentId == wblbId)
				.map((x) => {
					return {
						label: x.name,
						value: x.code,
					};
				});
		}
		if (options.gzlxs) {
			options.gzlxs = dics
				.filter((x) => x.parentId == gzlxId)
				.map((x) => {
					return {
						label: x.name,
						value: x.code,
					};
				});
		}
		if (options.wzdws) {
			options.wzdws = dics
				.filter((x) => x.parentId == wzdwId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
		if (options.wzxzs) {
			options.wzxzs = dics
				.filter((x) => x.parentId == wzxzId)
				.map((x) => {
					return {
						label: x.name,
						value: x.name,
					};
				});
		}
	});
};
export const initDicOne = (options) => {
	Promise.all([queryDics()]).then((res: any) => {
		const dics = res[0].data;
		const ckyyId = dics.find((x) => x.code == 'CKYY')?.id;
		if (options.ckyys) {
			options.ckyys = dics
				.filter((x) => x.parentId == ckyyId)
				.map((x) => {
					return {
						label: x.name,
						value: x.code,
					};
				});
		}
	});
};
export const initOrgansAndUers = (options: any, callback: Function) => {
	Promise.all([queryPagers({ PageSize: 1000 }), queryOrgans({ PageSize: 1000 }), queryDics()]).then((res: any) => {
		if (options.tqrs) {
			options.tqrs = res[0].data.data.map((x: any) => {
				return {
					label: x.name,
					value: x.name,
					key:x.id
				};
			});
		}
		if (options.tqdws) {
			options.tqdws = res[1].data.data.map((x: any) => {
				return {
					label: x.name,
					value: x.name,
				};
			});
		}
		const dics = res[2].data;
		const ckyyId = dics.find((x) => x.code == 'CKYY')?.id;
		if (options.ckyys) {
			options.ckyys = dics
				.filter((x) => x.parentId == ckyyId)
				.map((x) => {
					return {
						label: x.name,
						value: x.code,
					};
				});
		}
		if (callback) {
			callback();
		}
	});
};
